/*
 * 描述： 自定義網關過濾器
 * 修改人： Weng.weng
 * 修改时间： 2020年10月21日
 * 项目： gateway-server
 */
package com.tuozixuan.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

/**
 * 自定義網關過濾器<br>
 * 
 * @author Weng.weng
 * @version [版本号, 2020年10月21日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Component
public class CheckAuthGatewayFilterFactory extends AbstractGatewayFilterFactory<CheckAuthGatewayFilterFactory.Config> {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    
    public CheckAuthGatewayFilterFactory() {
        super(Config.class);
    }
    
    @Override
    public GatewayFilter apply(Config config) {
        
        logger.info("CheckAuthGatewayFilterFactory:{}", config.getName());
        return (exchange, chain) -> {
            ServerHttpRequest request = exchange.getRequest().mutate().build();
            return chain.filter(exchange.mutate().request(request).build());
        };
    }
    
    public static class Config {
        
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
        
    }


}
